import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import {
  registerMicroApps,
  addGlobalUncaughtErrorHandler,
  start
} from 'qiankun'
// 微应用注册信息
import apps from './app'
registerMicroApps(apps, {
  beforeLoad: (app) => {
    // 进度条
    NProgress.configure({ showSpinner: false })
    NProgress.inc(0.2)
    NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false })
    NProgress.start()
    return Promise.resolve()
  },
  afterMount: (app) => {
    NProgress.done()
    return Promise.resolve()
  }
})
// 全局的未捕获异常处理器，微应用发生报错的时候亦可以用这个api捕捉。
addGlobalUncaughtErrorHandler((event) => {
  console.error(event)
  const { message: msg } = event
  if (msg && msg.includes('died in status LOADING_SOURCE_CODE')) {
    throw new Error('微应用加载失败，请检查应用是否可运行!')
  }
})
start()
